﻿//首页下单
function index_changenum(itemid, p_name, cur) {
    alert('11');
    var num = $(".js_index_num_" + itemid).val();//变量前数量
    
    //var p_price = $(".price_product_" + itemid).html();//产品单价
    var stocks = $("#hid_stocks_" + itemid).val();
    if (cur == "+") {
        
        if ((Number(stocks) + 1000) >= (Number(num) + 1)) {
            $(".js_index_num_" + itemid).val(Number(num) + 1);
            $(".js_index_num_input_" + itemid).val(Number(num) + 1);
            num = Number(num) + 1;
            
        }
        else {
            //大于库存不做处理
            return
        }
        
    }

    else if (cur == "-" && num > "0") {
        $(".js_index_num_" + itemid).val(Number(num) - 1);
        $(".js_index_num_input_" + itemid).val(Number(num) - 1);
        num = Number(num) - 1;
        if (num == 0) {
            //if(confirm("是否删除改商品？")){
            //    $("#shopping_div_" + itemid).hide();
            //}
            $("#shopping_div_" + itemid).hide();
        }
    }
    else if (num == "") {
        alert("输入有误!");
    }
   
    $.ajax({
        url: "program/operate.ashx",
        data: {
            a: "add_shopping_list",
            p_on: cur,//+ 1
            p_id: itemid,//ID
            p_ct: num//数量
        },
        cache: false,
        error: function () { alert('下单失败，重新下单'); },
        success: function (result) {
            if (result.indexOf('userid is null') >= 0) {
                $("#icon_num").hide();
                alert("请先登录");
                location.href = "default.aspx?pageid=login";
            }
            else {
                var icon_num = result.split('-');
                if (icon_num[1] == 0) {
                    $("#icon_num").hide();
                }
                else {
                    $("#icon_num").show();
                }
                $("#icon_num").html(icon_num[1]);
                getinfo(['all'])
            }
            //if (result.indexOf('ok') >= 0) {
            //    var icon_num = result.split('-');
            //    if (icon_num[1] == 0) {
            //        $("#icon_num").hide();
            //    }
            //    else {
            //        $("#icon_num").show();
            //    }
            //    $("#icon_num").html(icon_num[1]);
            //    getinfo(['all'])
            //}
            //else {
                
            //    if (result.indexOf('userid is null') >= 0);
            //    {
            //        $("#icon_num").hide();
            //        alert("请先登录");
            //        location.href = "default.aspx?pageid=login";
            //    }
            //}
        }
    });
   
}

function product_list_number() {
    $.ajax({
        url: "program/operate.ashx",
        data: {
            a: "product_list_number",
        },
        cache: false,
        error: function () {
            //alert("网络不佳");
        },
        success: function (result) {
            if (result == 0 || result.indexOf('userid is null') >= 0) {
                $("#icon_num").hide();
            }
            else {
                $("#icon_num").show();
                $("#icon_num").html(result);
            }
           
        }
    })
}


//远程请求数据
function getinfo(data) {
    var datastr = data.join(",")
    $.ajax({
        url: "program/operate.ashx",
        data: {
            a: "getshopinginfo",
            product: datastr
        },
        dataType: "json",
        cache: false,
        error: function () {
            //alert("error");
        },
        success: function (result) {
            setinfo(result)
        }
    })
}
//设置信息
function setinfo(jsonStr) {
    //alert(jsonStr.shangpin_price);
    //var jsonObj = JSON.parse(jsonStr);
    //alert(jsonObj);
    $("#shangpin_price").html('￥' + jsonStr.shangpin_price);
    $("#yunfei_price").html('￥' + jsonStr.yunfei_price);
    $("#zhifu_price").html('￥' + jsonStr.zhifu_price);
    $("#zhifu_price2").html('￥' + jsonStr.zhifu_price);
}



//退出安卓


document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {

    WeixinJSBridge.call('hideToolbar');

});

